package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.mapper.TbAuctionMapper;
import com.dk.mapper.TbCarsMapper;
import com.dk.pojo.TbAuction;
import com.dk.pojo.TbCars;
import com.dk.service.TbAuctionService;
import com.dk.vo.TbCarsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.management.Query;
import java.util.ArrayList;
import java.util.List;

@Service
public class TbAuctionServiceImpl implements TbAuctionService {

    @Resource
    private TbCarsMapper tbCarsMapper;

    @Resource
    private TbAuctionMapper tbAuctionMapper;

    @Override
    public List<TbCarsVO> show() {
        List<TbCarsVO> tbCarsVO = new ArrayList<>();
        TbCarsVO tbCarsVO1 = new TbCarsVO();
        QueryWrapper<TbCars> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(true, "auction_not", 1);
        List<TbCars> list1 = tbCarsMapper.selectList(queryWrapper);
        for (TbCars car : list1) {
            tbCarsVO1.setId(car.getId());
            BeanUtils.copyProperties(car, tbCarsVO1);

            QueryWrapper<TbAuction> tbAuctionQueryWrapper = new QueryWrapper<>();
            tbAuctionQueryWrapper.eq(true,"cid",car.getId());
            List<TbAuction> tbAuctionList = tbAuctionMapper.selectList(tbAuctionQueryWrapper);
            for (TbAuction tbAuction:tbAuctionList){
                BeanUtils.copyProperties(tbAuction, tbCarsVO1);

            }
            tbCarsVO.add(tbCarsVO1);
        }
        return tbCarsVO;
    }

    @Override
    public TbCarsVO toshow(Long id) {

        TbCarsVO tbCarsVO =tbCarsMapper.selectAll(id);

        return tbCarsVO;
    }
}
